<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{$Think.lang.usergl}</title>
    <link rel="stylesheet" href="__ADMIN__/vendor/layui/css/layui.css">
    <link rel="stylesheet" href="__ADMIN__/custom/css/style.css">
</head>
<body style="padding:10px 10px;">
    <form action="{:url('category/sort')}" method="post">
        <a style="float:left;margin-right: 10px;" href="{:url('category/create')}" 	class="layui-btn layui-btn-normal">添加栏目</a>
        <div style="float:left"><button class="layui-btn layui-btn-danger" type="submit" >{$Think.lang.sort}</button></div>
<table class="layui-table" lay-size="sm">
    <colgroup>
        <col width="80">
        <col width="80">
        <col>
        <col width="100">
        <col width="150">
    </colgroup>
    <thead>
    <tr pid="0">
        <th style="text-align: center;">{$Think.lang.shen}</th>
        <th style="text-align: center;">ID</th>
        <th>{$Think.lang.catename}</th>
        <th style="width:50px;">{$Think.lang.type}</th>
        <th style="width:50px;">{$Think.lang.sort}</th>
        <th style="width:100px;">{$Think.lang.caoz}</th>
    </tr>
    </thead>
    <tbody>
    {volist name="cate" id="vo"}
    <tr pid="{$vo.pid}" id="{$vo.id}">
        <td><button class="layui-btn layui-btn-sm shensuo" type="button" style="width:50px;height:30px;">
                <i class="layui-icon">+</i>
              </button>
        </td>
        <td style="text-align: center;">{$vo.id}</td>
        <td>{$vo.cate_name}</td>
        <td>{$vo.type}</td>
        <td style="width:50px;"><input type="text" name="{$vo.id}" value="{$vo.sort}" style="width:50px;" ></td>
        <td>
            <a href="{:url('category/edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-warm layui-btn-mini">编辑</a>
            <a href="{:url('category/delete',['id'=>$vo.id])}" class="layui-btn layui-btn-danger layui-btn-mini del">删除</a></td>
    </tr>
    {/volist}
    </tbody>
</table>

</form>
<script src="__ADMIN__/vendor/js/jquery.js"></script>
<script src="__ADMIN__/vendor/layui/layui.js"></script>
<script src="__ADMIN__/custom/js/admin.js"></script>
<script>
    layui.use('layer', function(){
        var layer = layui.layer;
        $('.del').on('click',function () {
            var url=$(this).attr('href');
            layer.confirm('确定要删除该管理员吗?', {icon: 3, title:'温馨提示'}, function(index){
                //do something
                location.href=url;
                layer.close(index);
            });
            return false;
        })
    });
    $(function(){
        $(window.parent.document).find('#righttitle').text($('title').text());
   });
//    栏目伸缩
// 隐藏非顶级栏目
$('tr[pid!=0]').hide();
// 子栏目展开
$(".shensuo").click(function(){
    var flag=$(this).find('i').text();
    var index=$(this).parents('tr').attr('id');
    if(flag=="+"){
        $(this).find('i').text('-');
        //展开子栏目录
        $('tr[pid='+index+']').fadeIn('slow');
    }else{
        $(this).find('i').text("+");
        hidecate(index);
    }
});
//隐藏子栏目 pid 父级分类id,递归隐藏子栏目
function hidecate(pid) {
        $('tr[pid='+pid+']').each(function () {
            hidecate($(this).attr('id'));
        })
        $('tr[pid='+pid+']').fadeOut('slow');
        $('tr[pid='+pid+']').find('.shensuo').find('i').text("+");

    }
</script>
</body>
</html>